<?php


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\ActivityVideoComment;
use App\User;

/**
 * 类 ActivityVideoComment 的描述
 */
class ActivityVideoCommentController extends CommonController
{

    /**
     * 获取某条视频的评论
     */
    public function getCommentList(Request $request)
    {
        $data = $request->input();

        $lists = ActivityVideoComment::with('user', 'rUser', 'video')->where('post_id', $data['id'])
            ->orderBy('top', 'desc')->orderBy('created_at', 'asc')->paginate(10);

        $actions = User::getPermissionAction(1421, 1);

        return view('activityvideocomment.list')->with('lists', $lists)->with('id', $data['id'])->with('actions', $actions);
    }

    /**
     * 将一条评论置顶
     */
    public function postTop(Request $request)
    {
        $data = $request->input();

        ActivityVideoComment::where('id', $data['tcid'])->update(['top'=>1]);

        return AjaxCallbackMessage('置顶成功', true, url('activityvideocomment/comment-list?id='.$data['vid']));
    }



    /**
     * 删除一条评论
     */
    public function postDelete(Request $request)
    {
        $data = $request->input();
        ActivityVideoComment::where('id', $data['dcid'])->delete();
        ActivityVideoComment::where('upid', $data['dcid'])->delete();
        return AjaxCallbackMessage('删除成功', true, url('activityvideocomment/comment-list?id='.$data['dvid']));
    }


    public function getEdit(Request $request)
    {
        $data = $request->input();

        $list = ActivityVideoComment::where('id', $data['id'])->first();

        return view('activityvideocomment/edit')->with('list', $list);


    }


    public function postEdit(Request $request)
    {

        $this->validate($request, ['wonderful' => 'required|in:1,0']);

        $data = $request->input();
        $comment =  ActivityVideoComment::where('id', $data['id'])->first();
        ActivityVideoComment::where('id', $data['id'])->update(['wonderful'=>$data['wonderful']]);

        return AjaxCallbackMessage('编辑成功', true, url('activityvideocomment/comment-list?id='.$comment->post_id));
    }

}